package com.swq.java.code.chapter15.code17;

import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;

public class ColourTester {
    enum Colour {RED, BLUE, YELLOW, GREEN} //表示颜色的枚举类

    public static void main(String[] args) {
        // EnumSet的使用
        EnumSet<Colour> colourSet = EnumSet.allOf(Colour.class);
        for (Colour c : colourSet)
            System.out.println(c);

        // EnumMap的使用
        EnumMap<Colour, String> colourMap = new EnumMap<Colour, String>(Colour.class);
        colourMap.put(Colour.RED, "红色");
        colourMap.put(Colour.BLUE, "蓝色");
        colourMap.put(Colour.YELLOW, "黄色");
        colourMap.put(Colour.GREEN, "绿色");

        Set<Map.Entry<Colour, String>> set = colourMap.entrySet();
        for (Map.Entry entry : set)  //entry表示Map中的一对键与值
            System.out.println(entry.getKey() + ":" + entry.getValue());

        System.out.println("=====================");
        for (Colour colour : colourMap.keySet()) {
            System.out.println(colour + " : " + colourMap.get(colour));
        }

    }
}